<?php require_once('../connections/con_gl.php'); ?>
<?php
$act = $_GET[act];
$url = "index.php?component=pengemudi";

/* Validasi */
if (trim($_POST['nama']) == '') {
	$error[] = '- Nama harus diisi !!!';
}
if (trim($_POST['sim']) == '') {
	$error[] = '- SIM harus diisi !!!';
}
if (trim($_POST['ktp']) == '') {
	$error[] = '- KTP harus diisi !!!';
}
if (trim($_POST['alamat']) == '') {
	$error[] = '- Alamat harus diisi !!!';
}
if (trim($_POST['email']) <> '' AND !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST[email])){ 
	$error[] = '- Format Email abcde@xxxx.com  !!!';
}

/*End validasi */
if (isset($error)) {
	echo "<b>Error</b>: <br />".implode("<br />", $error);
}else{
	if($act =='add') {
	$query = "INSERT INTO gl_pengemudi (id, nama, tipesim, sim, ktp, alamat, tlp, email) VALUES (NULL, '$_POST[nama]', '$_POST[tipesim]','$_POST[sim]','$_POST[ktp]', '$_POST[alamat]', '$_POST[tlp]', '$_POST[email]')";
	}else if($act=='edit'){
	$query ="UPDATE gl_pengemudi SET nama='$_POST[nama]', tipesim='$_POST[tipesim]', sim='$_POST[sim]', ktp='$_POST[ktp]', alamat='$_POST[alamat]', tlp='$_POST[tlp]', email='$_POST[email]' WHERE id='$_POST[id]'";
	}else{
	$query = "delete from gl_pengemudi where id='$_POST[id]'";
	}
	mysql_select_db($database_con_gl, $con_gl);
	$runquery = mysql_query($query, $con_gl);
	if($runquery) {
		echo "<img src=\"images/ok.png\" align=\"middle\"> Data berhasil disimpan ...";
	}else{
		echo "<img src=\"images/alert.png\" align=\"middle\"> Data gagal disimpan !!!";
	}
}
?>
<?php if($runquery) { ?><script type="text/javascript">setTimeout("location.href='<?php echo $url;?>'", 2000);</script><?php } ?>